package com.ebpm.designer
{
	import flash.display.Graphics;
	
	import spark.components.Application;

	public class WF
	{
		//常量序号
		public static var sqe:Number = 0;
		
		/*常量*/
		[Embed(source="img/ud.png")]
		public static const Icon_Resize_UpDown:Class;
		[Embed(source="img/lr.png")]
		public static const Icon_Resize_LeftRight:Class;
		[Embed(source="img/mouseMove.png")]
		public static const Icon_Mouse_Move:Class;
		[Embed(source="img/bg3.png")]
		public static const Icon_BackGround:Class;
		
		[Embed(source="img/autoTask.png")]
		public static const Icon_ServiceTask:Class;
		[Embed(source="img/startEvent.png")]
		public static const Icon_StartEvent:Class;
		[Embed(source="img/subStartEvent.png")]
		public static const Icon_SubStartEvent:Class;
		[Embed(source="img/endEvent.png")]
		public static const Icon_EndEvent:Class;
		[Embed(source="img/subEndEvent.png")]
		public static const Icon_SubEndEvent:Class;
		[Embed(source="img/fork_before.png")]
		public static const Icon_ForkBeforeEvent:Class;
		[Embed(source="img/forkTask.png")]
		public static const Icon_ForkTaskEvent:Class;
		[Embed(source="img/laneTask.png")]
		public static const Icon_LaneTaskEvent:Class;
		[Embed(source="img/laneForkTask.png")]
		public static const Icon_LaneForkTaskEvent:Class;
		[Embed(source="img/forkGather.png")]
		public static const Icon_ForkGatherEvent:Class;
		[Embed(source="img/userTask.png")]
		public static const Icon_UserTask:Class;
		[Embed(source="img/laneBefore.png")]
		public static const Icon_LaneBefore:Class;
		[Embed(source="img/laneAfter.png")]
		public static const Icon_LaneAfter:Class;
		
		
		[Embed(source="img/nw_resize.png")]
		public static const Icon_LT_Resize:Class;
		[Embed(source="img/se_resize.png")]
		public static const Icon_RD_Resize:Class;
		
		public static const ITEM_SIZE:Number = 6;																						//【NodeContainer】连线框大小
		public static const MIN_NODE_W:Number = 120;																			//【NodeContainer】默认宽度
		public static const MIN_NODE_H:Number = 50;																				//【NodeContainer】默认高度
		
		public static const SelectRectBgColor:String = "#00A6A6";															//【SelectRect】默认背景颜色
		
		//线的属性
		public static const LINE_COLOR:Number = 0x272727;
		public static const LINE_OVER_COLOR:Number = 0xFF0099;
		public static const LINE_CLICK_COLOR:Number = 0x009900;
		public static const LINEXU_COLOR:Number = 0x8C8C8C;
		public static const LINE_SIZE:Number = 1;
		public static const LINE_HEAD_W:Number = 12;
		public static const LINE_HEAD_H:Number = 3;
		public static const LINE_EXT_SIZE:Number = 30;
		public static const LINE_TXT_W:Number = 100;
		public static const LINE_TXT_H:Number = 25;
		
		//item连线点的属性
		public static const ITEM_BORDER_COLOR:String = "#A0A0A0";
		public static const ITEM_BGCOLOR:String = "#000066";
		public static const ITEM_BG_OVER_COLOR:String = "#FF0099";
		
		//任务属性
		public static const USERTASK_BG:String = "#C2C2C2";
		public static const USERTASK_BORDER_BG:String = "#515151";
		public static const USERTASK_BG_OVER:String = "#00A2A2";
		public static const USERTASK_IMG_WIDTH:Number = 28;
		public static const USERTASK_IMG_HEIGHT:Number = 28;
		public static const USERTASK_IMG_X:Number = 4;
		public static const USERTASK_IMG_Y:Number = 4;

		//判断节点属性
		public static const START_EVENT_W:Number = 46;
		public static const START_EVENT_H:Number = 46;
		
		//文本框属性
		public static const TXT_LABEL_W:Number = 60;
		public static const TXT_H:Number = 20;
		public static const TXT_INPUT_W:Number = 120;
		public static const TXT_INPUT_H:Number = 20;
		public static const TXT_LR_PADDING:Number = 10;
		public static const TXT_UD_PADDING:Number = 10;
		
		public static const MENU_ITEM_WIDTH:Number = 46;
		public static const MENU_ITEM_HEIGHT:Number = 46;
		
		[Embed(source="img/menu/endEvent.png")]
		public static const MenuEndEvent:Class;
		[Embed(source="img/menu/forkAfter.png")]
		public static const MenuForkAfter:Class;
		[Embed(source="img/menu/forkBefore.png")]
		public static const MenuForkBefore:Class;
		[Embed(source="img/menu/forkTask.png")]
		public static const MenuForkTask:Class;
		[Embed(source="img/menu/laneAfter.png")]
		public static const MenuLaneAfter:Class;
		[Embed(source="img/menu/laneBefore.png")]
		public static const MenuLaneBefore:Class;
		[Embed(source="img/menu/laneTask.png")]
		public static const MenuLaneTask:Class;
		[Embed(source="img/menu/serviceTask.png")]
		public static const MenuServiceTask:Class;
		[Embed(source="img/menu/startEvent.png")]
		public static const MenuStartEvent:Class;
		[Embed(source="img/menu/subEndEvent.png")]
		public static const MenuSubEndEvent:Class;
		[Embed(source="img/menu/subStartEvent.png")]
		public static const MenuSubStartEvent:Class;
		[Embed(source="img/menu/userTask.png")]
		public static const MenuUserTask:Class;
		[Embed(source="img/menu/save.png")]
		public static const MenuSave:Class;
		[Embed(source="img/menu/open.png")]
		public static const MenuOpen:Class;
		[Embed(source="img/menu/imageCut.png")]
		public static const MenuImageCut:Class;
		
		[Embed(source="img/menu/endEvent1.png")]
		public static const MenuEndEvent1:Class;
		[Embed(source="img/menu/forkAfter1.png")]
		public static const MenuForkAfter1:Class;
		[Embed(source="img/menu/forkBefore1.png")]
		public static const MenuForkBefore1:Class;
		[Embed(source="img/menu/forkTask1.png")]
		public static const MenuForkTask1:Class;
		[Embed(source="img/menu/laneAfter1.png")]
		public static const MenuLaneAfter1:Class;
		[Embed(source="img/menu/laneBefore1.png")]
		public static const MenuLaneBefore1:Class;
		[Embed(source="img/menu/laneTask1.png")]
		public static const MenuLaneTask1:Class;
		[Embed(source="img/menu/serviceTask1.png")]
		public static const MenuServiceTask1:Class;
		[Embed(source="img/menu/startEvent1.png")]
		public static const MenuStartEvent1:Class;
		[Embed(source="img/menu/subEndEvent1.png")]
		public static const MenuSubEndEvent1:Class;
		[Embed(source="img/menu/subStartEvent1.png")]
		public static const MenuSubStartEvent1:Class;
		[Embed(source="img/menu/userTask1.png")]
		public static const MenuUserTask1:Class;
		[Embed(source="img/menu/save1.png")]
		public static const MenuSave1:Class;
		[Embed(source="img/menu/open1.png")]
		public static const MenuOpen1:Class;
		[Embed(source="img/menu/imageCut1.png")]
		public static const MenuImageCut1:Class;
		
		
		public static var xmlDefinitionsData:String = "";																										//工作流定义信息【xmlDefinitionsData】和【xmlPositionData】
		public static var xmlPositionData:String = "";
		
		/** @注意：页面js解析以后，用图片定位流程走向的功能下掉 **/
		public static var xmlLineJson:String = "";																													//【xmlLineJson】和【xmlTaskJson】是为了给前台js解析用的数据 
		public static var xmlTaskJson:String = "";
		
		public static var wp:WorkPanel;
		public static var app:Application;
		public function WF()
		{
		}
		
		public static function getId():Number {
			WF.sqe = WF.sqe + 1;
			if(WF.sqe > 9) {
				WF.sqe = 1;
			}
			return WF.sqe;
		}
		
		/**
		 * 虚线画法
		 * @param solidLen		实线长度
		 * @param brokenLen		虚线间隔长度
		 */
		public static function drawBrokenLine(g:Graphics,fromX:Number,fromY:Number,toX:Number,toY:Number,solidLen:Number=5,brokenLen:Number=0):void
		{
			//如果间隔为0,直接画实线
			if(brokenLen == 0 || solidLen == 0)
			{
				g.moveTo(fromX,fromY);
				g.lineTo(toX,toY);
				return;
			}
			//如果间隔不为0,画虚线
			var xOffset:Number = toX - fromX;
			var yOffset:Number = toY - fromY ;
			//正切角度值
			var atan:Number = Math.atan2(yOffset,xOffset);
			//线的总长度
			var totalLen:Number =Math.sqrt(Math.pow(xOffset,2)+Math.pow(yOffset,2));
			//已经画线长度
			var len:Number = 0;
			//当前循环是否画实线
			var isDrawSolid:Boolean = true;
			var tempFX:Number = fromX;
			var tempFY:Number = fromY;
			while(totalLen>len)
			{
				len = isDrawSolid ? len + solidLen : len + brokenLen;
				//利用三角函数,计算该段终点坐标
				var tempTX:Number = Math.cos(atan)*len + fromX;
				var tempTY:Number = Math.sin(atan)*len + fromY;
				if(isDrawSolid)
				{
					g.moveTo(tempFX,tempFY);
					g.lineTo(tempTX,tempTY);
				}
				isDrawSolid = !isDrawSolid;
				tempFX = tempTX ;
				tempFY = tempTY ;
			}
		}
		
		//判断两个长方形是否重合
		public static function intersects(x:Number, y:Number, width:Number, height:Number, toX:Number, toY:Number, toWidth:Number, toHeight:Number):Boolean {
			var tw:Number = width;
			var th:Number = height;
			var rw:Number = toWidth;
			var rh:Number = toHeight;
			if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
				return false;
			}
			var tx:Number = x;
			var ty:Number = y;
			var rx:Number = toX;
			var ry:Number = toY;
			rw += rx;
			rh += ry;
			tw += tx;
			th += ty;
			return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
		}
		
		
		
	}
}